package com.platform.auth;

import cn.hutool.core.util.StrUtil;
import com.platform.auth.feign.OAuthClientFeignClient;
import com.platform.auth.feign.UserFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.core.env.Environment;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author： yuanlai
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = {UserFeignClient.class, OAuthClientFeignClient.class})
@Slf4j
@EnableSwagger2
public class AuthApp {
    public static void main(String[] args) throws UnknownHostException {
        Environment env = SpringApplication.run(AuthApp.class, args).getEnvironment();
        String port = env.getProperty("server.port");
        String contextPath = env.getProperty("server.servlet.context-path");
        contextPath = StrUtil.isBlank(contextPath) ? Strings.EMPTY : contextPath;
        log.info("Access URLs:\n----------------------------------------------------------\n\t"
                        + "Local: \t\thttp://127.0.0.1:{}\n\t"
                        + "External: \thttp://{}:{}\n\t"
                        + "swagger: \thttp://{}:{}{}/doc.html\n----------------------------------------------------------",
                port,
                InetAddress.getLocalHost().getHostAddress(), port,
                InetAddress.getLocalHost().getHostAddress(), port, contextPath
        );
    }
}
